var steelCase = steelCase || {};

$(function() {
  steelCase.executePOST = function(urlForm, idForm, resultDiv, messageText) {
    steelCase.showSpinner();
    $.ajax({
      type : "POST",
      url : urlForm,
      data : $("#" + idForm).serialize(),
      success : function(msg) {
        if (JSON.stringify(msg) === '"OK"') {
          $("#" + resultDiv).html("<div id='toFade' class='alert alert-success'>" + messageText + "</div>");
          $("#toFade").delay(1500).fadeOut(500, "swing");
        }
      },
      error : function(xhr, ajaxOptions, thrownError) {
        $("#" + resultDiv).html("<div id='toFade' class='alert alert-error'>Error en la comunicación con el servidor</div>");
        $("#toFade").delay(1500).fadeOut(500, "swing");
      }
    });
    steelCase.hideSpinner();
  };
  
  steelCase.showSpinner = function(){    
    $("#screenCenter").html("<img src='../static/images/loading.gif'>").css('display','block');
  };

  steelCase.hideSpinner = function(){
    $("#screenCenter").html("").css('display','none');
  };
});
